//
//  JLProductCollectionViewController.m
//  JL网易彩票progress
//
//  Created by sunjinliang on 15/11/11.
//  Copyright © 2015年 sunjinliang. All rights reserved.
//

#import "JLProductCollectionViewController.h"
#import "JLProduct.h"
#import "JLProductsCollectionViewCell.h"
@interface JLProductCollectionViewController ()
@property(nonatomic,strong)NSArray * products;
@end

@implementation JLProductCollectionViewController

static NSString * const reuseIdentifier = @"product";

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.collectionView.backgroundColor=[UIColor whiteColor];
    UINib * nib=[UINib nibWithNibName:@"JLProductsCollectionViewCell" bundle:[NSBundle mainBundle]];
    [self.collectionView  registerNib:nib forCellWithReuseIdentifier:reuseIdentifier];
 
   
}
//懒加载
-(NSArray *)products{
    if (!_products) {
        NSString * path=[[NSBundle mainBundle]pathForResource:@"products.json" ofType:nil];
    NSData * data=[NSData dataWithContentsOfFile:path];
        NSArray * arryDict=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        NSMutableArray * arrayModels=[NSMutableArray array];
        for (NSDictionary * dict in arryDict) {
            JLProduct * product=[JLProduct productWithDict:dict];
            [arrayModels addObject:product];
        }
        _products=arrayModels;
    }
    return _products;
}
-(instancetype)init{
    UICollectionViewFlowLayout * flow=[[UICollectionViewFlowLayout alloc]init];
    flow.itemSize=CGSizeMake(80, 80);
    if (self==[super initWithCollectionViewLayout:flow]) {
        
    }
    return self;
}

#pragma mark <UICollectionViewDataSource>



- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {

    return self.products.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    JLProductsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    if (cell==nil) {
        cell=[[JLProductsCollectionViewCell alloc]init];
    }
    JLProduct * product=self.products[indexPath.item];
    cell.prodect=product;
    
    return cell;
}

#pragma mark <UICollectionViewDelegate>

/*
// Uncomment this method to specify if the specified item should be highlighted during tracking
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
	return YES;
}
*/

/*
// Uncomment this method to specify if the specified item should be selected
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
*/

/*
// Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item
- (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath {
	return NO;
}

- (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
	return NO;
}

- (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
	
}
*/

@end
